home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / console / svgatext.3 / svgatext / SVGATextMode-1.3 / contrib / consoletools / dscrn.c next >
Encoding:
C/C++ Source or Header  |  1996-02-06  |  1.3 KB  |  58 lines

  1. /*
  2.  * Screen-capture program for Linux text consoles
  3.  
  4.  * The "vcs" and "vcsa" drivers give read/write access to a vt's video memory,
  5.  * somewhat like direct access to segment 0xb800 under DOS. The vcs version is
  6.  * character-only, the vcsa version is character-attribute. There's one for
  7.  * each vt, and they're numbered 7,0+ and 7,128+, respectively, with
  8.  * /dev/vcs[a]0 corresponding to "/dev/tty". 
  9.  */
  10.  
  11. /*
  12.     dscrn.c   (c) Bob McCracken
  13.  
  14. Usage: dscrn [ttyno] > foo
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <unistd.h>
  19. #include <termios.h>
  20. #include <stdlib.h>
  21. #include <fcntl.h>
  22. #include <string.h>
  23. #include <sys/ioctl.h>
  24. #include <linux/major.h>
  25.  
  26. #define PSIZE    4096        /* screen page size */
  27. #define BSIZE    (PSIZE << 3)    /* 8 pages per vt */
  28.  
  29. char buf [BSIZE];
  30.  
  31. void main (int argc, char **argv)
  32. {
  33.   int c, x, y; char dev [16]; struct winsize w;
  34.   
  35.   x = (argc < 2) ? 0 : atoi(argv[1]);
  36.  
  37.   ioctl (0, TIOCGWINSZ, &w);
  38.   
  39.   if (x >= 0 && x <= MAX_CHRDEV)    /* ttyno in range? */
  40.     {           
  41.       sprintf (dev, "/dev/vcs%d", x);    /* only want chars, not attrs */
  42.  
  43.       if ((x = open (dev, 0)) >= 0)
  44.     { 
  45.       y = read (x, buf, BSIZE); close (x);
  46.       
  47.       for (c = x = 0; x < y; x++)
  48.          {
  49.            if (putchar (buf[x]) == '\n') c = 0;    /* (Actually, there
  50.                             shouldn't be any
  51.                             newlines in it.) */
  52.  
  53.         else if (++c >= w.ws_col) { c = 0; putchar ('\n'); }
  54.              }
  55.     }
  56.     }
  57. }
  58.